package com.lwx.test;

import com.lwx.tree.BST;

import java.util.Arrays;
import java.util.Random;

public class DemoBST {
    public static void main(String[] args) {

//         * *******36
//         * ******/  \
//         ******25    55
//        ******/  \   / \
//        ****10

        BST<Integer> tree = new BST<>();
        int n = 1000;
        for (int i = 0; i < n; i++) {
            tree.add(new Random().nextInt(10000));
        }
        int[] treeArray = new int[tree.getSize()];
        int size = tree.getSize();

        //将树从小到大的元素取出来，放在数组里
        for (int i = 0; i < size; i++) {
            treeArray[i] = tree.removeMin();
        }
        System.out.println(Arrays.toString(treeArray));

        for (int i = 0; i < treeArray.length-1; i++) {
            if(treeArray[i] > treeArray[i+1]){
                throw new IllegalArgumentException("Error");
            }
        }
        System.out.println("Completed!");
    }
}
